/**    
 * @{#} MyFollowingActivity.java Create on 2014-7-8 下午12:19:12    
 *          
 * @author <a href="mailto:evan0502@qq.com">Evan</a>   
 * @version 1.0    
 */
package com.smiier.skin;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import cn.o.app.net.INetTask;
import cn.o.app.net.NetTaskListener;
import cn.skinapp.R;

import com.smiier.skin.constant.Constant;
import com.smiier.skin.net.CounterGetTask;
import com.smiier.skin.net.CounterGetTask.CounterGetRequest;
import com.smiier.skin.net.CounterGetTask.CounterGetResponse;
import com.smiier.skin.net.CounterGetTask.TypeCount;
import com.smiier.skin.net.CounterGetTask.ValueCount;
import com.smiier.skin.ui.BasicActivity;
import com.smiier.skin.util.GlobalSettings;
import com.smiier.skin.utils.CommonUtility;
import com.umeng.analytics.MobclickAgent;

public class MyFollowingActivity extends BasicActivity {

	private TextView text_question_num, text_doctor_num, text_patient_num;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_my_following);

		init();
		setNavTitle("我的关注");

		text_question_num = (TextView) findViewById(R.id.text_question_num);
		text_doctor_num = (TextView) findViewById(R.id.text_doctor_num);
		text_patient_num = (TextView) findViewById(R.id.text_patient_num);

	}

	@Override
	protected void onResume() {
		super.onResume();
		
//		MobclickAgent.onResume(this);

		CounterGetTask task = new CounterGetTask();
		CounterGetRequest req = new CounterGetRequest();
		ArrayList<Integer> types = new ArrayList<Integer>();
		types.add(1002);
		types.add(2006);
		types.add(2007);
		req.types = types;
		ArrayList<Long> uids = new ArrayList<Long>();
		uids.add(GlobalSettings.sUid);
		req.uids = uids;
		task.setRequest(req);
		task.addListener(new NetTaskListener<CounterGetTask.CounterGetRequest, CounterGetTask.CounterGetResponse>() {

			@Override
			public void onException(
					INetTask<CounterGetRequest, CounterGetResponse> task,
					Exception e) {

			}

			@Override
			public void onComplete(
					INetTask<CounterGetRequest, CounterGetResponse> task,
					CounterGetResponse response) {
				if (!CommonUtility.isNull(response)
						|| response.ResultCode == 200) {
					ArrayList<TypeCount> Res = response.Res;
					try {

						for (int i = 0; i < Res.size(); i++) {
							TypeCount type = Res.get(i);
							if (type.Value.size() > 0) {
								ValueCount count = type.Value.get(0);
								long key = type.Key;

								if (key == 1002) {
									text_question_num.setText("问题（"
											+ count.Value + "）");
								} else if (key == 2007) {
									text_doctor_num.setText("医生（" + count.Value
											+ "）");
								} else if (key == 2006) {
									text_patient_num.setText("患者（"
											+ count.Value + "）");
								}
							}
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		});
		add(task);
	}

	public void onClick(View view) {
		super.onClick(view);
		int id = view.getId();
		if (id == R.id.text_question_num) {
			startActivity(new Intent(activity,
					MyFollowingQuestionActivity.class));
		} else if (id == R.id.text_doctor_num) {
			Intent intent = new Intent(activity,
					MyFollowingDoctorActivity.class);
			intent.putExtra(Constant.IDENTITY_KEY, true);
			startActivity(intent);
		} else if (id == R.id.text_patient_num) {
			startActivity(new Intent(activity, MyFollowingDoctorActivity.class));
		}
	}

/*	@Override
	public void onPause() {
		super.onPause();
		MobclickAgent.onPause(getContext());
	}*/
}
